package org.bot.server.init;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.bot.client.driver.api.client.ClientOpenApi;
import org.bot.client.driver.api.server.ServerReceiveClientData;
import org.bot.client.driver.api.server.ServerUpdateClientStatus;
import org.bot.server.client.entity.BotClient;
import org.bot.server.client.mapper.BotClientMapper;
import org.bot.server.event.entity.BotEvent;
import org.bot.server.event.mapper.BotEventMapper;
import org.bot.server.utils.Mode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author 沧月
 * @create 0002 2023/11/2 18:07
 * @description <本地启动模式上线全部客户端>
 */
@Component
public class LocationJobCommandLineRunner implements CommandLineRunner {

    @Value("${bot.mode}")
    private String mode;

    @Autowired
    BotClientMapper botClientMapper;

    @Autowired
    ServerUpdateClientStatus clientStatus;

    @Override
    public void run(String... args) throws Exception {
        String mode = Mode.LOCATION.getMode();
        if (!mode.equals(this.mode)) {
            return;
        }

        //所有客户端自动上线
        QueryWrapper<BotClient> wrapper = new QueryWrapper<>();
        wrapper.ne("status", 3);
        List<Map<String, Object>> list = botClientMapper.selectMaps(wrapper);
        list.forEach(map -> {
            clientStatus.clientOnline(map.get("client_id").toString());
        });
    }
}
